package com.kedsoft.andaily.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.kedsoft.andaily.entity.Boardroom;
import com.kedsoft.andaily.entity.Project;
import com.kedsoft.andaily.entity.Router;
import com.kedsoft.andaily.entity.Task;
import com.kedsoft.andaily.service.BoardroomService;
import com.kedsoft.andaily.service.ProjectService;
import com.kedsoft.andaily.service.RouterService;
import com.kedsoft.andaily.service.TaskService;
import com.kedsoft.andaily.util.DateUtil;
import com.kedsoft.andaily.util.ExcelUtils;
import com.kedsoft.andaily.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * Created by Administrator on 2019/6/11.
 */
@RequestMapping("/report")
@Controller
public class ReportController {

    @Autowired
    TaskService taskService;

    @Autowired
    BoardroomService boardroomService;

    @Autowired
    RouterService routerService;

    @Autowired
    ProjectService projectService;

    @RequestMapping("taskindex")
    public String taskindex(){
        return "report/taskindex";
    }

    /**
     * 派单月报表
     * @param routerid
     * @param taskdate
     * @return
     */
    @RequestMapping(value = "taskList")
    @ResponseBody
    public PageVo<Task> taskList(@RequestParam(required = false) Integer routerid,
                                 @RequestParam(required = false) String taskdate){
        PageVo<Task> pageVo = new PageVo<>();
        EntityWrapper<Task> wrapper = new EntityWrapper<>();
        if(routerid!=null && routerid!=0){
            wrapper.eq("routerid", routerid);
        }
        if(taskdate==null|| taskdate.trim().equals("")){
            List<Task> zero = new ArrayList<>();
            pageVo.setRows(zero);
            pageVo.setTotal(0);
            return pageVo;
        }
        wrapper.eq("taskdate",taskdate);
        List<Task> list = taskService.selectList(wrapper);
        pageVo.setRows(list);
        pageVo.setTotal(list.size());
        return pageVo;
    }

    @RequestMapping(value = "taskListExcel", method = RequestMethod.POST)
    public void getTaskListExcel(HttpServletResponse response,@RequestParam(required = false) Integer routerid,
                                 @RequestParam(required = false) String taskdate){
        EntityWrapper<Task> wrapper = new EntityWrapper<>();
        if(routerid!=null && routerid!=0){
            wrapper.eq("routerid", routerid);
        }
        if(taskdate==null|| taskdate.trim().equals("")){
            List<Task> zero = new ArrayList<>();
            return;
        }
        wrapper.eq("taskdate",taskdate);
        List<Task> list = taskService.selectList(wrapper);
        ExcelDataVo excelDataVo = new ExcelDataVo();
        excelDataVo.setName("运维派单月报表("+taskdate+")");
        List<String> titles = new ArrayList();
        titles.add("所属项目编码");
        titles.add("所属项目名称");
        titles.add("配电房名称");
        titles.add("所属单位名称");
        titles.add("所属巡视单位");
        titles.add("执行人员");
        titles.add("完成时间");
        titles.add("任务类型");
        titles.add("任务评分");
        excelDataVo.setTitles(titles);
        List<List<Object>> rows = new ArrayList();
        for (int i=0;i<list.size();i++){
            Task bean = list.get(i);
            List<Object> row = new ArrayList();
            row.add(bean.getProjectcode());
            row.add(bean.getProjectname());
            row.add(bean.getBoardname());
            row.add(bean.getFactoryname());
            row.add(bean.getRoutername());
            row.add(bean.getCname());
            row.add(DateUtil.format(bean.getStoptime(),"yyyy-MM-dd"));
            row.add(bean.getTasktypestr());
            row.add(bean.getAssess());
            rows.add(row);
        }
        excelDataVo.setRows(rows);
        try{
            ExcelUtils.exportExcel(response,"运维派单月报表("+taskdate+")",excelDataVo);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

    /**
     * 查询条件1
     * @return
     */
    @RequestMapping(value = "mapa")
    public String mapa(){
        return "report/mapa";
    }

    @RequestMapping(value = "roomtaskindex")
    public String roomtaskindex(){
        return "report/roomtaskindex";
    }

    @RequestMapping(value = "roomTaskList")
    @ResponseBody
    public PageVo<RoomTask> roomTaskList(@RequestParam(required = false) Integer routerid,
                                         @RequestParam(required = false) String taskdate){
        PageVo<RoomTask> pageVo = new PageVo<>();
        EntityWrapper<Boardroom> boardroomEntityWrapper = new EntityWrapper<>();
        if(routerid!=null&& routerid!=0) {
            boardroomEntityWrapper.eq("routerid", routerid);
        }
        if(taskdate==null || taskdate.trim().equals("")){
            List<RoomTask> roomTaskList = new ArrayList<>();
            pageVo.setRows(roomTaskList);
            pageVo.setTotal(0);
            return pageVo;
        }
        List<Boardroom> boardroomList = new ArrayList<>();
        boardroomList = boardroomService.selectList(boardroomEntityWrapper);
        //创建配电房任务地图
        Map<String,RoomTask> roomTaskMap = new HashMap<>();
        for (Boardroom bean:boardroomList) {
            String roomId = String.valueOf(bean.getId());
            RoomTask roomTaskBean = new RoomTask();
            roomTaskBean.setBooardname(bean.getBoardname());
            roomTaskBean.setFactoryname(bean.getFactoryname());
            roomTaskBean.setProjectcode(bean.getProjectcode());
            roomTaskBean.setRoutername(bean.getRoutername());
            roomTaskBean.setUsertype(bean.getUsertype());
            roomTaskMap.put(roomId,roomTaskBean);
        }
        //查询出日期内的所有任务(日常任务）
        EntityWrapper<Task> taskEntityWrapper = new EntityWrapper<>();
        if(routerid!=null&& routerid!=0) {
            taskEntityWrapper.eq("routerid", routerid);
        }
        taskEntityWrapper.eq("taskdate",taskdate);
        //taskEntityWrapper.in("tasktype",new Integer[]{40,50,60,70,80});
        List<Task>  listTask = taskService.selectList(taskEntityWrapper);
        if(listTask!=null){
            for(Task bean:listTask){
                try {
                    if (bean.getStatus() > 30) {
                        String boardId = String.valueOf(bean.getBoardid());
                        RoomTask roomTaskTemp = roomTaskMap.get(boardId);
                        if(roomTaskMap ==null)
                            continue;
                        if (bean.getTasktype() != null) {
                            switch (bean.getTasktype()) {
                                case 10:
                                case 20:
                                case 30:
                                case 90:
                                    roomTaskTemp.setOp(roomTaskTemp.getOp() + 1);
                                    roomTaskMap.put(boardId, roomTaskTemp);
                                    break;
                                case 40:
                                    if (bean.getAssess() > 0 && bean.getAssess() < 5) {
                                        roomTaskTemp.setOp40(2);
                                    } else {
                                        roomTaskTemp.setOp40(1);
                                    }
                                    roomTaskMap.put(boardId, roomTaskTemp);
                                    break;
                                case 50:
                                    if (bean.getAssess() > 0 && bean.getAssess() < 5) {
                                        roomTaskTemp.setOp50(2);
                                    } else {
                                        roomTaskTemp.setOp50(1);
                                    }
                                    roomTaskMap.put(boardId, roomTaskTemp);
                                    break;
                                case 60:
                                    if (bean.getAssess() > 0 && bean.getAssess() < 5) {
                                        roomTaskTemp.setOp60(2);
                                    } else {
                                        roomTaskTemp.setOp60(1);
                                    }
                                    roomTaskMap.put(boardId, roomTaskTemp);
                                    break;
                                case 70:
                                    if (bean.getAssess() > 0 && bean.getAssess() < 5) {
                                        roomTaskTemp.setOp70(2);
                                    } else {
                                        roomTaskTemp.setOp70(1);
                                    }
                                    roomTaskMap.put(boardId, roomTaskTemp);
                                    break;
                                case 80:
                                    if (bean.getAssess() > 0 && bean.getAssess() < 5) {
                                        roomTaskTemp.setOp80(2);
                                    } else {
                                        roomTaskTemp.setOp80(1);
                                    }
                                    roomTaskMap.put(boardId, roomTaskTemp);
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }catch (Exception e){
                    System.out.println(e.getMessage());
                }
            }
        }
        Collection<RoomTask> roomTaskCollection = roomTaskMap.values();
        List<RoomTask> rows = new ArrayList<>(roomTaskCollection);
        pageVo.setRows(rows);
        pageVo.setTotal(rows.size());
        return pageVo;
    }

    @RequestMapping(value = "roomTaskListExcel", method = RequestMethod.POST)
    public void roomTaskListExcel(HttpServletResponse response,@RequestParam(required = false) Integer routerid,
                                 @RequestParam(required = false) String taskdate){
        EntityWrapper<Boardroom> boardroomEntityWrapper = new EntityWrapper<>();
        if(routerid!=null&& routerid!=0) {
            boardroomEntityWrapper.eq("routerid", routerid);
        }
        if(taskdate==null || taskdate.trim().equals("")){
            List<RoomTask> roomTaskList = new ArrayList<>();
            return;
        }
        List<Boardroom> boardroomList = new ArrayList<>();
        boardroomList = boardroomService.selectList(boardroomEntityWrapper);
        //创建配电房任务地图
        Map<String,RoomTask> roomTaskMap = new HashMap<>();
        for (Boardroom bean:boardroomList) {
            String roomId = String.valueOf(bean.getId());
            RoomTask roomTaskBean = new RoomTask();
            roomTaskBean.setBooardname(bean.getBoardname());
            roomTaskBean.setFactoryname(bean.getFactoryname());
            roomTaskBean.setProjectcode(bean.getProjectcode());
            roomTaskBean.setRoutername(bean.getRoutername());
            roomTaskBean.setUsertype(bean.getUsertype());
            roomTaskMap.put(roomId,roomTaskBean);
        }
        //查询出日期内的所有任务(日常任务）
        EntityWrapper<Task> taskEntityWrapper = new EntityWrapper<>();
        if(routerid!=null&& routerid!=0) {
            taskEntityWrapper.eq("routerid", routerid);
        }
        taskEntityWrapper.eq("taskdate",taskdate);
        //taskEntityWrapper.in("tasktype",new Integer[]{40,50,60,70,80});
        List<Task>  listTask = taskService.selectList(taskEntityWrapper);
        if(listTask!=null){
            for(Task bean:listTask){
                if(bean.getStatus()>30){
                    String boardId = String.valueOf(bean.getBoardid());
                    RoomTask roomTaskTemp = roomTaskMap.get(boardId);
                    switch (bean.getTasktype()){
                        case 10:
                        case 20:
                        case 30:
                        case 90:
                            roomTaskTemp.setOp(roomTaskTemp.getOp()+1);
                            roomTaskMap.put(boardId,roomTaskTemp);
                            break;
                        case 40:
                            if(bean.getAssess()>0&& bean.getAssess()<5) {
                                roomTaskTemp.setOp40(2);
                            }else{
                                roomTaskTemp.setOp40(1);
                            }
                            roomTaskMap.put(boardId,roomTaskTemp);
                            break;
                        case 50:
                            if(bean.getAssess()>0&& bean.getAssess()<5) {
                                roomTaskTemp.setOp50(2);
                            }else{
                                roomTaskTemp.setOp50(1);
                            }
                            roomTaskMap.put(boardId,roomTaskTemp);
                            break;
                        case 60:
                            if(bean.getAssess()>0&& bean.getAssess()<5) {
                                roomTaskTemp.setOp60(2);
                            }else{
                                roomTaskTemp.setOp60(1);
                            }
                            roomTaskMap.put(boardId,roomTaskTemp);
                            break;
                        case 70:
                            if(bean.getAssess()>0&& bean.getAssess()<5) {
                                roomTaskTemp.setOp70(2);
                            }else{
                                roomTaskTemp.setOp70(1);
                            }
                            roomTaskMap.put(boardId,roomTaskTemp);
                            break;
                        case 80:
                            if(bean.getAssess()>0&& bean.getAssess()<5) {
                                roomTaskTemp.setOp80(2);
                            }else{
                                roomTaskTemp.setOp80(1);
                            }
                            roomTaskMap.put(boardId,roomTaskTemp);
                            break;
                        default:
                            break;
                    }

                }
            }
        }
        Collection<RoomTask> roomTaskCollection = roomTaskMap.values();
        List<RoomTask> list = new ArrayList<>(roomTaskCollection);
        ExcelDataVo excelDataVo = new ExcelDataVo();
        excelDataVo.setName("配电房巡视月报表("+taskdate+")");
        List<String> titles = new ArrayList();
        titles.add("配电房名称");
        titles.add("所属项目编号");
        titles.add("所属单位名称");
        titles.add("所属巡视单位");
        titles.add("派单次数");
        titles.add("设备清扫");
        titles.add("日常巡视");
        titles.add("红外测温");
        titles.add("开关核对");
        titles.add("环境清扫");
        excelDataVo.setTitles(titles);
        List<List<Object>> rows = new ArrayList();
        for (int i=0;i<list.size();i++){
            RoomTask bean = list.get(i);
            List<Object> row = new ArrayList();
            row.add(bean.getRoutername());
            row.add(bean.getProjectcode());
            row.add(bean.getFactoryname());
            row.add(bean.getRoutername());
            row.add(bean.getOp());
            row.add(getImg(bean.getOp40()));
            row.add(getImg(bean.getOp50()));
            row.add(getImg(bean.getOp60()));
            row.add(getImg(bean.getOp70()));
            row.add(getImg(bean.getOp80()));
            rows.add(row);
        }
        excelDataVo.setRows(rows);
        try{
            ExcelUtils.exportExcel(response,"配电房巡视月报表("+taskdate+")",excelDataVo);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

    private String getImg(Integer op){
        if(op==0){
            return "X";
        }else {
            return "✓";
        }
    }

    @RequestMapping(value = "routertjindex")
    public String routertjindex(){
        return "report/routertjindex";
    }

    /**i
     * 查询条件
     * @return
     */
    @RequestMapping(value = "map")
    public String map(){
        return "report/map";
    }

    @RequestMapping(value = "routerTj")
    @ResponseBody
    public PageVo<RouterTJ> routerTj(@RequestParam(required = false) String taskdate){
        PageVo<RouterTJ> pageVo = new PageVo<>();
        EntityWrapper<Router> routerEntityWrapper = new EntityWrapper<>();
        routerEntityWrapper.eq("status",1);
        if(taskdate==null || taskdate.trim().equals("")){
            List<RouterTJ> routerTjTaskList = new ArrayList<>();
            pageVo.setRows(routerTjTaskList);
            pageVo.setTotal(0);
            return pageVo;
        }
        List<Router> routerList = new ArrayList<>();
        routerList = routerService.selectList(routerEntityWrapper);
        //创建配电房任务地图
        Map<String,RouterTJ> routerTjMap = new HashMap<>();
        for (Router bean:routerList) {
            String routerid = String.valueOf(bean.getId());
            RouterTJ routerTJ = new RouterTJ();
            routerTJ.setRoutername(bean.getName());
            routerTjMap.put("router_"+routerid,routerTJ);
        }
        //查询出日期内的所有任务(日常任务）
        EntityWrapper<Task> taskEntityWrapper = new EntityWrapper<>();
        taskEntityWrapper.eq("taskdate",taskdate);
        List<Task>  listTask = taskService.selectList(taskEntityWrapper);
        if(listTask!=null){
            for(Task task: listTask){
                RouterTJ routerTJTemp = routerTjMap.get("router_"+task.getRouterid());
                routerTJTemp.setAllsum(routerTJTemp.getAllsum()+1);
                switch (task.getStatus()){
                    case 10:
                    case 20:
                    case 30:
                         routerTJTemp.setUndosum(routerTJTemp.getUndosum()+1);
                         routerTJTemp.setTotal(routerTJTemp.getTotal()+5);
                         break;
                    case 40:
                        routerTJTemp.setDonesum(routerTJTemp.getDonesum()+1);
                        routerTJTemp.setTotal(routerTJTemp.getTotal()+5);
                        break;
                    case 50:
                        routerTJTemp.setDonesum(routerTJTemp.getDonesum()+1);
                        if(task.getAssess()<5){
                            routerTJTemp.setWarnningsum(routerTJTemp.getWarnningsum()+1);
                        }
                        routerTJTemp.setScore(routerTJTemp.getScore()+task.getAssess());
                        routerTJTemp.setTotal(routerTJTemp.getTotal()+5);
                        break;
                    default:
                        break;
                }
            }
        }
        Collection<RouterTJ> routerTJSCollection = routerTjMap.values();
        List<RouterTJ> rows = new ArrayList<>(routerTJSCollection);
        pageVo.setRows(rows);
        pageVo.setTotal(rows.size());
        return pageVo;
    }

    @RequestMapping(value = "routerTjExcel", method = RequestMethod.POST)
    public void routerTjExcel(HttpServletResponse response,
                                  @RequestParam(required = false) String taskdate){
        EntityWrapper<Router> routerEntityWrapper = new EntityWrapper<>();
        routerEntityWrapper.eq("status",1);
        if(taskdate==null || taskdate.trim().equals("")){
            List<RouterTJ> routerTjTaskList = new ArrayList<>();
            return;
        }
        List<Router> routerList = new ArrayList<>();
        routerList = routerService.selectList(routerEntityWrapper);
        //创建配电房任务地图
        Map<String,RouterTJ> routerTjMap = new HashMap<>();
        for (Router bean:routerList) {
            String routerid = String.valueOf(bean.getId());
            RouterTJ routerTJ = new RouterTJ();
            routerTJ.setRoutername(bean.getName());
            routerTjMap.put("routertj_"+routerid,routerTJ);
        }
        //查询出日期内的所有任务(日常任务）
        EntityWrapper<Task> taskEntityWrapper = new EntityWrapper<>();
        taskEntityWrapper.eq("taskdate",taskdate);
        List<Task>  listTask = taskService.selectList(taskEntityWrapper);
        if(listTask!=null){
            for(Task task: listTask){
                RouterTJ routerTJTemp = routerTjMap.get("routertj_"+task.getRouterid());
                routerTJTemp.setAllsum(routerTJTemp.getAllsum()+1);
                switch (task.getStatus()){
                    case 10:
                    case 20:
                    case 30:
                        routerTJTemp.setUndosum(routerTJTemp.getUndosum()+1);
                        routerTJTemp.setTotal(routerTJTemp.getTotal()+5);
                        break;
                    case 40:
                        routerTJTemp.setDonesum(routerTJTemp.getDonesum()+1);
                        routerTJTemp.setTotal(routerTJTemp.getTotal()+5);
                        break;
                    case 50:
                        routerTJTemp.setDonesum(routerTJTemp.getDonesum()+1);
                        if(task.getAssess()<5){
                            routerTJTemp.setWarnningsum(routerTJTemp.getWarnningsum()+1);
                        }
                        routerTJTemp.setScore(routerTJTemp.getScore()+task.getAssess());
                        routerTJTemp.setTotal(routerTJTemp.getTotal()+5);
                        break;
                    default:
                        break;
                }
            }
        }
        Collection<RouterTJ> routerTJSCollection = routerTjMap.values();
        List<RouterTJ> list = new ArrayList<>(routerTJSCollection);
        ExcelDataVo excelDataVo = new ExcelDataVo();
        excelDataVo.setName("巡视单位月统计("+taskdate+")");
        List<String> titles = new ArrayList();
        titles.add("巡视单位");
        titles.add("派单总次数");
        titles.add("派单任务总分");
        titles.add("完成派单数");
        titles.add("未完成派单数");
        titles.add("延时完成派单数");
        titles.add("完成任务评分");
        excelDataVo.setTitles(titles);
        List<List<Object>> rows = new ArrayList();
        for (int i=0;i<list.size();i++){
            RouterTJ bean = list.get(i);
            List<Object> row = new ArrayList();
            row.add(bean.getRoutername());
            row.add(bean.getAllsum());
            row.add(bean.getTotal());
            row.add(bean.getDonesum());
            row.add(bean.getUndosum());
            row.add(bean.getWarnningsum());
            row.add(bean.getScore());
            rows.add(row);
        }
        excelDataVo.setRows(rows);
        try{
            ExcelUtils.exportExcel(response,"巡视单位月统计("+taskdate+")",excelDataVo);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }

    @RequestMapping(value = "projecttjindex")
    public String projecttjindex(){
        return "report/projecttjindex";
    }


    @RequestMapping(value = "projectTj")
    @ResponseBody
    public PageVo<ProjectTj> projectTj(@RequestParam(required = false) String taskdate){
        PageVo<ProjectTj> pageVo = new PageVo<>();
        EntityWrapper<Project> projectEntityWrapper = new EntityWrapper<>();
        projectEntityWrapper.eq("status",1);
        if(taskdate==null || taskdate.trim().equals("")){
            List<ProjectTj> projectTjTaskList = new ArrayList<>();
            pageVo.setRows(projectTjTaskList);
            pageVo.setTotal(0);
            return pageVo;
        }
        List<Project> projectList = new ArrayList<>();
        projectList = projectService.selectList(projectEntityWrapper);
        //创建配电房任务地图
        Map<String,ProjectTj> projectTjMap = new HashMap<>();
        for (Project bean:projectList) {
            String projectId = String.valueOf(bean.getId());
            ProjectTj projectTj = new ProjectTj();
            projectTj.setProjectcode(bean.getProjectcode());
            projectTj.setProjectname(bean.getProjectname());
            projectTjMap.put("project_"+projectId,projectTj);
        }
        //查询出日期内的所有任务(日常任务）
        EntityWrapper<Task> taskEntityWrapper = new EntityWrapper<>();
        taskEntityWrapper.eq("taskdate",taskdate);
        List<Task>  listTask = taskService.selectList(taskEntityWrapper);
        if(listTask!=null){
            for(Task task: listTask){
                ProjectTj projectTjTemp = projectTjMap.get("project_"+task.getProjectid());
                projectTjTemp.setAllsum(projectTjTemp.getAllsum()+1);
                switch (task.getStatus()){
                    case 10:
                    case 20:
                    case 30:
                        projectTjTemp.setUndosum(projectTjTemp.getUndosum()+1);
                        projectTjTemp.setTotal(projectTjTemp.getTotal()+5);
                        break;
                    case 40:
                        projectTjTemp.setDonesum(projectTjTemp.getDonesum()+1);
                        projectTjTemp.setTotal(projectTjTemp.getTotal()+5);
                        break;
                    case 50:
                        projectTjTemp.setDonesum(projectTjTemp.getDonesum()+1);
                        if(task.getAssess()<5){
                            projectTjTemp.setWarnningsum(projectTjTemp.getWarnningsum()+1);
                        }
                        projectTjTemp.setScore(projectTjTemp.getScore()+task.getAssess());
                        projectTjTemp.setTotal(projectTjTemp.getTotal()+5);
                        break;
                    default:
                        break;
                }
            }
        }
        Collection<ProjectTj> routerTJSCollection = projectTjMap.values();
        List<ProjectTj> rows = new ArrayList<>(routerTJSCollection);
        pageVo.setRows(rows);
        pageVo.setTotal(rows.size());
        return pageVo;
    }

    @RequestMapping(value = "projectTjExcel", method = RequestMethod.POST)
    public void projectTjExcel(HttpServletResponse response,
                              @RequestParam(required = false) String taskdate){
        EntityWrapper<Project> projectEntityWrapper = new EntityWrapper<>();
        projectEntityWrapper.eq("status",1);
        if(taskdate==null || taskdate.trim().equals("")){
            List<ProjectTj> projectTjTaskList = new ArrayList<>();
            return;
        }
        List<Project> projectList = new ArrayList<>();
        projectList = projectService.selectList(projectEntityWrapper);
        //创建配电房任务地图
        Map<String,ProjectTj> projectTjMap = new HashMap<>();
        for (Project bean:projectList) {
            String projectId = String.valueOf(bean.getId());
            ProjectTj projectTj = new ProjectTj();
            projectTj.setProjectcode(bean.getProjectcode());
            projectTj.setProjectname(bean.getProjectname());
            projectTjMap.put("project_"+projectId,projectTj);
        }
        //查询出日期内的所有任务(日常任务）
        EntityWrapper<Task> taskEntityWrapper = new EntityWrapper<>();
        taskEntityWrapper.eq("taskdate",taskdate);
        List<Task>  listTask = taskService.selectList(taskEntityWrapper);
        if(listTask!=null){
            for(Task task: listTask){
                ProjectTj projectTjTemp = projectTjMap.get("project_"+task.getProjectid());
                projectTjTemp.setAllsum(projectTjTemp.getAllsum()+1);
                switch (task.getStatus()){
                    case 10:
                    case 20:
                    case 30:
                        projectTjTemp.setUndosum(projectTjTemp.getUndosum()+1);
                        projectTjTemp.setTotal(projectTjTemp.getTotal()+5);
                        break;
                    case 40:
                        projectTjTemp.setDonesum(projectTjTemp.getDonesum()+1);
                        projectTjTemp.setTotal(projectTjTemp.getTotal()+5);
                        break;
                    case 50:
                        projectTjTemp.setDonesum(projectTjTemp.getDonesum()+1);
                        if(task.getAssess()<5){
                            projectTjTemp.setWarnningsum(projectTjTemp.getWarnningsum()+1);
                        }
                        projectTjTemp.setScore(projectTjTemp.getScore()+task.getAssess());
                        projectTjTemp.setTotal(projectTjTemp.getTotal()+5);
                        break;
                    default:
                        break;
                }
            }
        }
        Collection<ProjectTj> routerTJSCollection = projectTjMap.values();
        List<ProjectTj> list = new ArrayList<>(routerTJSCollection);
        ExcelDataVo excelDataVo = new ExcelDataVo();
        excelDataVo.setName("项目月统计("+taskdate+")");
        List<String> titles = new ArrayList();
        titles.add("项目编号");
        titles.add("项目名称");
        titles.add("派单总次数");
        titles.add("派单任务总分");
        titles.add("完成派单数");
        titles.add("未完成派单数");
        titles.add("延时完成派单数");
        titles.add("完成任务评分");
        excelDataVo.setTitles(titles);
        List<List<Object>> rows = new ArrayList();
        for (int i=0;i<list.size();i++){
            ProjectTj bean = list.get(i);
            List<Object> row = new ArrayList();
            row.add(bean.getProjectcode());
            row.add(bean.getProjectname());
            row.add(bean.getAllsum());
            row.add(bean.getTotal());
            row.add(bean.getDonesum());
            row.add(bean.getUndosum());
            row.add(bean.getWarnningsum());
            row.add(bean.getScore());
            rows.add(row);
        }
        excelDataVo.setRows(rows);
        try{
            ExcelUtils.exportExcel(response,"项目月统计("+taskdate+")",excelDataVo);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
}
